document.observe("dom:loaded", function () {
    myManager = new ObjectsManager();
    myManager.start();


//    var newContainer;
//    (function(){
//        new Ajax.Request("data/spec/container1.json", {
//            method: 'get',
//            onSuccess: function (transport) {
//                try {
//                    var o = transport.responseText.evalJSON(true);
//                    newContainer = new MyElement();
//                    newContainer.initAttributeList(o);
//                    myManager.add(newContainer);
//                }
//                catch (err) {
//                    console.log(err);
//                }
//            },
//            onFailure: function () {
//                alert("JSON Fail");
//            }
//        });
//    })();

    var newEle;
    (function(){
        new Ajax.Request("data/spec/spec1.json", {
            method: 'get',
            onSuccess: function (transport) {
                try {
                    var o = transport.responseText.evalJSON(true);
                    newEle = new MyElement();
                    newEle.initAttributeList(o);
                    myManager.add(newEle);
                   // newContainer.addChild(newEle);


                }
                catch (err) {
                    console.log(err);
                }


            },
            onFailure: function () {
                alert("JSON Fail");
            }
        });
    })();
    var newEle2;
    (function(){
        new Ajax.Request("data/spec/spec2.json", {
            method: 'get',
            onSuccess: function (transport) {
                try {
                    var o = transport.responseText.evalJSON(true);
                    newEle2 = new MyElement();
                    newEle2.initAttributeList(o);
                    myManager.add(newEle2);
                    // newContainer.addChild(newEle);


                }
                catch (err) {
                    console.log(err);
                }


            },
            onFailure: function () {
                alert("JSON Fail");
            }
        });
    })();

    (function(){
        new Ajax.Request("data/spec/opList1.json", {
            method: 'get',
            onSuccess: function (transport) {
                try {
                    var o = transport.responseText.evalJSON(true);
                    newEle.initOperationList(o);
                }
                catch (err) {
                    console.log(err);
                }

                var e = myManager.getElementById("element1");
                console.log(e.id);

//                new webkit_click(e.id, {
//                    onClick: function(){
//                       // e.execute("swing");
//                        console.log("winner");
//                        //alert("sdasd");
//                        //editor.show();
//                    }
//                });

//
//              Event.observe("element1",'touch',function(){
//                   console.log("winner");
//                         alert("winner");
//             })
            },
            onFailure: function () {
                alert("JSON Fail");
            }
        });
    })();
    (function(){
        new Ajax.Request("data/spec/opList1.json", {
            method: 'get',
            onSuccess: function (transport) {
                try {
                    var o = transport.responseText.evalJSON(true);
                    newEle2.initOperationList(o);
                }
                catch (err) {
                    console.log(err);
                }


            },
            onFailure: function () {
                alert("JSON Fail");
            }
        });
    })();

    (function(){

        $j("#test1").bind('click',function(){
            //console.log(e);
            editor.hide();


        })

    })();


});